package ypmits.components.droparea {
	import ypmits.components.Component;
	import ypmits.components.ComponentSkin;
	import ypmits.components.IComponent;
	import ypmits.simpledraw.Cross;

	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;

	/**
	 * @author Dave Lenz
	 */
	public class DropArea extends Component implements IComponent {
		
		private var background : Sprite;
		private var edge : Shape;
		private var iconholder : Sprite;

		
		
		public function DropArea( width : Number = 50, height : Number = 50 )
		{
			var s : ComponentSkin = new ComponentSkin();
			s.width = width;
			s.height = height;
			
			super( s );
			
			draw( );
		}

		
		
		private function draw() : void 
		{
			addChild( background = new Sprite( ) );
			addChild( edge = new Shape( ) );
			addChild( iconholder = new Sprite( ) );
			
			var cross : Cross = new Cross( 13, 1, 0xFFFFFF );
			iconholder.addChild( cross );
			
			redraw();
			
			background.filters = [ new DropShadowFilter( 6, 45, 0, .45, 6, 6, 1, 3, true ) ];
			filters = [ new DropShadowFilter( 4, 45, 0, .35, 5, 5, 1, 3, true ) ];
		}

		
		
		private function redraw() : void 
		{
			background.graphics.clear();
			background.graphics.beginFill( 0x555555 );
			background.graphics.drawRoundRect(0, 0, skin.width, skin.height, 12 );
			background.graphics.endFill();
			
			edge.graphics.clear();
			edge.graphics.lineStyle( 4, 0xFFFFFF, 1, true );
			edge.graphics.drawRoundRect(0, 0, skin.width, skin.height, 12 );
			
			iconholder.x = skin.width * .5;
			iconholder.y = skin.height * .5;
		}
		
		
		
		public function set icon( icon : DisplayObject ) : void {
			icon.x = -(icon.width * .5);
			icon.y = -(icon.height * .5);
			
			iconholder.addChild( icon );
			
			redraw();
		}
	}
}
